﻿$(function () {
    var viewModel = function () {
        var self = this;

        self.organization = ko.validatedObservable(new miniSched.organizationModel());
        self.volunteers = ko.observableArray([]);
        self.addVolunteer = function () {
            self.volunteers.push(new miniSched.volunteerModel({
                OrganizationId: self.organization().Id()
            }));
        };

        self.saveVolunteers = function () {
            $.each(self.volunteers(), function (key, val) {
                if (!val.isPersisted()) {
                    val.save();
                }
            });
        };
    };

    ko.applyBindings(new viewModel());
});
